package hong.jun.basic.base.service.impl;


import hong.jun.basic.base.query.BaseQuery;
import hong.jun.basic.base.service.IBaseService;
import hong.jun.basic.util.PageList;
import hong.jun.basic.base.mapper.BaseMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.List;


public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public void save(T t) {
        mapper.save(t);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public void delete(Serializable id) {
        mapper.remove(id);
    }

    @Override
    public T getById(Serializable id) {
        return (T) mapper.loadById(id);
    }

    @Override
    public List<T> getAll() {
        return mapper.loadAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        Long count = mapper.queryCount(query);
        if (count == null || count < 1) {
            return new PageList<T>();
        }
        List<T> data = mapper.queryData(query);
        return new PageList<>(count, data);
    }

    @Override
    public void deletes(Serializable[] ids) {
        mapper.deletes(ids);
    }

}
